﻿Ext.define('app.prm.project_task.ImportTask',
{
    extend: 'Ext.window.Window',
    title: '导入问题',
    autoScroll: true,
    modal: true,
    width: 500,
    height: 300,
    autoHeight: true,
    layout: 'fit',
    projectId: 0,
    bodyStyle: 'padding:50px 0 0 0',
    initComponent: function () {
        var me = this;
        me.items = [this.getUploadForm()];
        me.buttons = [
            {
                text: '下载模板', scope: this, handler: function ()
                {
                    window.location.href = "/api/services/app/projectTask/GetDownTemplate";
                }
            },
            { text: '确定', scope: this, handler: me.onSave },
            { text: '关闭', handler: function () { me.close(); } }
        ]
        me.callParent();
    },
    getUploadForm: function () {
        var me = this;
        if (!this.uploadForm) {
            this.uploadForm = new Ext.form.Panel({
                defaultType: 'textfield',
                border: false,
                defaults: { anchor: '100%' },
                fieldDefaults: {
                    labelWidth: 90,
                    labelAlign: "right",
                    flex: 1,
                    margin: 6
                },
                items: [
                    { xtype: 'hidden', name: 'projectId', value: me.projectId },
                    {
                        xtype: 'filefield', fieldLabel: '选择文档', name: 'ProjectFile', buttonText: '浏览'
                    }
                ]
            });
        }
        return this.uploadForm;
    },
    onSave: function () {
        var me = this;
        me.uploadForm.getForm().submit({
            url: '/api/services/app/projectTask/Import',
            success: function (form, response) {
                var obj = response.result.result;

                var win = Ext.create("app.prm.project_task.ImportConfirm", { trees: obj.tree, tasks: obj.task, projectId: me.projectId });

                win.on("savesuccess", function ()
                {
                    me.fireEvent("savesuccess");
                    win.close();
                });
                win.show();
            }
        });
    }
});